Repository navigation
feat(desktop-commander): OAuth 2.1 front door for hosted MCP clients (#13404) - #13488
Merged
Merged
Conversation
…13404) Claude and ChatGPT connect to the MCP endpoint from their own servers and cannot pass a Cloudflare Access login at /mcp — every path on commander.security.cab answered them with a 302 to the Access login, and there was no OAuth discovery to find. The Worker now runs an OAuth 2.1 authorization server (src/oauth.ts): - Public discovery: /.well-known/oauth-protected-resource (both shapes) and /.well-known/oauth-authorization-server. - POST /register: dynamic client registration, public clients, https / loopback-http redirect URIs, stored in the new OAUTH_KV namespace (desktop-commander-oauth). - GET/POST /authorize: the approval page — the one path that stays behind Access (the app is re-scoped to /authorize separately). The Worker verifies the Access JWT itself (RS256 vs the team JWKS, audience, owner email) before rendering; approval is a CSRF-nonce form POST issuing a single-use PKCE-bound code. - POST /token: authorization-code exchange (PKCE S256; the code is consumed on any exchange attempt) plus rotating refresh tokens. Codes and tokens are stored in KV under their SHA-256. - /mcp takes a live OAuth Bearer or the new MACHINE_BEARER secret; anything else gets a 401 with the resource_metadata pointer. The bridge door and the proxy core are unchanged. The publish workflow now also stages MACHINE_BEARER (GitHub environment secret; canonical value in fleet secrets as desktop-commander.machine-bearer) into the version secrets file. wrangler.toml and cloudflare.config.ts gain the OAUTH_KV binding and the ACCESS_AUD / ACCESS_TEAM_DOMAIN vars, kept in step. Tests: 21 green (proxy contract re-pointed at the new gate, plus an OAuth suite with a real in-test RSA keypair standing in for the Access team key: discovery, DCR validation, assertion rejection, plain-PKCE rejection, full approve-exchange-call flow, code single-use, wrong-verifier burn, refresh rotation, deny redirect).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 10 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #13404: hosted MCP clients (Claude, ChatGPT) connect server-side and cannot pass the Cloudflare Access login at /mcp — they got a 302 to the Access login on every path and found no OAuth discovery. This PR gives the Worker an OAuth 2.1 authorization-server front (
src/oauth.ts):/.well-known/oauth-protected-resource(both shapes) +/.well-known/oauth-authorization-server, public.POST /register(RFC 7591), public clients, https / loopback-http redirect URIs, clients stored in the newOAUTH_KVnamespace (desktop-commander-oauth, created in the account).GET/POST /authorizerenders the owner's approval page. It stays behind Access (app re-scoped to/authorizein a separate recorded step) and the Worker verifies the Access JWT itself: RS256 against the team JWKS, audience of the authorize app, owner email. Approval is a CSRF-nonce form POST issuing a single-use, PKCE-bound code (10 min).POST /token: authorization-code exchange (PKCE S256; code consumed on any attempt) → opaque access token (1 h) + rotating refresh token (30 d); codes/tokens stored in KV under their SHA-256.MACHINE_BEARERWorker secret (constant-time compare); otherwise 401 with theresource_metadatapointer. Bridge door + proxy core unchanged.MACHINE_BEARER(GitHub environment secret, set; canonical value in fleet secrets asdesktop-commander.machine-bearer) alongside the bridge pair.wrangler.toml/cloudflare.config.tsgain the KV binding andACCESS_AUD/ACCESS_TEAM_DOMAINvars in step.Verification:
npm test21/21 (proxy contract re-pointed at the new gate; OAuth suite uses a real in-test RSA keypair as the Access team key — discovery, DCR validation, assertion rejection, plain-PKCE rejection, full approve→exchange→call flow, code single-use, wrong-verifier burn, refresh rotation, deny redirect) andnpm run typecheckclean, both on the laptop.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.